<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	</body>
	<script src="../../lib/jq/jquery-1.11.3.min.js"></script>
	<script src="alert.js"></script>
<script>
/**
 * verify the input value
 */
$(function(){
	/*autoClean();*/
    window.alert("弹窗口!");
})

/**
 * 校验身份证信息
 */
function verifyIdCard(selectId){
	var flag = true;
	
	return flag;
}

/**
 * 校验用户名输入
 */
function verifyName(selectId){
	var flag = true;
	var name = getVal(selectId);
	console.log(name);
	if(isNull(selectId)){
//	if(name === "" || name === undefined){
		flag = false;
		setError(selectId,"用户名输入不能为空!");
	}
	if( /[^\u4e00-\u9fa5]/.test(name)){
		console.log(/[^\u4e00-\u9fa5]/.test(name));
		flag = false;
		setError(selectId,"用户名必须是中文!");
	}
	return flag;
}

/**
 * 校验是否为空
 */
function isNull(selectId){
	var flag = false;
	var str = getVal(selectId);
	if(str === undefined || str === "" ){
		flag = true;
	}
	return flag;
}

/**
 * 得到指定选择器的值
 * @param selectId
 * @returns
 */
function getVal(selectId){
	var val = $("#"+selectId).val();
	if(val === undefined){
		val = $("#"+selectId).text();
	}
	if(val === undefined){
		val = $("#"+selectId).html();
	}
	return val;
}

/**
 * 删除id选择器的下一个font并删除
 * @param selectId
 * @returns
 */
function cleanError(selectId){
	$("#"+selectId).nextAll("font").remove();
}

/**
 * 设置错误消息
 * @param selectId
 * @param msg
 * @returns
 */
function setError(selectId,msg){
	var fontObj = $("#"+selectId).next("font").html();
//	console.log(fontObj);
	if(fontObj != null && fontObj != undefined && fontObj != "" ){
		cleanError(selectId);
	}
	$("#"+selectId).after("<font color='red'>"+ msg +"</font>");
}


/**
 * 校验所有的input不能为空和null
 * @returns
 */
function verifyAll(){
	$(":input").each(function(index){
		$(this).focus(function(){
			var tag = this.
		});
	});
}

/**
 * 给指定ID绑定focus事件
 * @returns
 */
function autoClean(){
	$(":input").each(function(index){
		$(this).focus(function(){
			cleanError(this.id);
		});
	});
}


/* 校验所有的输入 */
function verifyIdAndShow(id,name,verifyLen){
	var flag = true;
	var value = $("#"+id).val().trim();
	if(value == "" || value == null || value == undefined){
		showAlert(name+"不能为空!");
		flag = false;
	}
	var len = value.length;
	if(len > verifyLen){
		showAlert(name+"长度不能大于"+verifyLen+"!");
		flag = false;
	}
	return flag;
}

verifyIdAndShow("relocation_site","安置点名称",40);
688
if(!verifyIdAndShow("relocation_site","安置点名称",40) ||
   !verifyIdAndShow("areaSelect1 option:selected","项目所属市县",40) || 
   !verifyIdAndShow("townSelect1 option:selected","项目所属乡镇",40) ||
   !verifyIdAndShow("areaSelect2 option:selected","迁出市县",40) ||
   !verifyIdAndShow("townSelect2 option:selected","迁出乡镇",40) ||
   !verifyIdAndShow("villageSelect2 option:selected","迁出行政村",40) ||
   !verifyIdAndShow("group_unit","迁出组",40) ||
   !verifyIdAndShow("section","房区号或栋号",40) ||
   !verifyIdAndShow("unit","单元号",10) ||
   !verifyIdAndShow("house_no","房屋编号",20) ||
   !verifyIdAndShow("house_area","住房面积",20) ||
   ){
	return;
}
</script>
</html>
